package mx.itesm.ccm.compu.gui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mx.itesm.ccm.compu.gui.Login;
import mx.itesm.ccm.compu.gui.MainPanel;
import mx.itesm.ccm.compu.gui.MainPanel.Rol;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Window;

public class AsesoriasApplication extends Application implements HttpServletRequestListener {
	
	 private static ThreadLocal<AsesoriasApplication> threadLocal = new ThreadLocal<AsesoriasApplication>(); 

	private Window mainWindow=new Window("Sistema de Reserva de Asesorias");


	@Override
	public void init() {
		
		setMainWindow(mainWindow);
		
		mainWindow.addWindow(new Login());
		setInstance(this); // So that we immediately have access to the current application 	


	}
	
	public void createWindow(Rol rol){
		
		MainPanel p=null;
		p = new MainPanel(rol);
		mainWindow.addComponent(p);
	}
	
	
	
	// @return the current application instance	  	
	  public static AsesoriasApplication getInstance() { 		
	    return threadLocal.get(); 	
	  } 	 	 

	  // Set the current application instance 	
	  public static void setInstance(AsesoriasApplication application) { 					
	      threadLocal.set(application); 		
	  }      
	
     
	  public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
		 AsesoriasApplication.setInstance(this);     
	  }      

  
	  public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
	    threadLocal.remove();     
	  }  
	

}
